package zhang.automobileservice;

import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.PopupWindow;

public class PresetWatchCarActivity extends FarterActivity implements View.OnClickListener {

    private ImageButton finish;
    private EditText et_name;
    private EditText et_tel;
    private Button bt_preset;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_preset_watch_car);
        initView();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.finish:
                finish();
                break;
            case R.id.et_name:
                break;
            case R.id.et_tel:
                break;
            case R.id.bt_preset:
                View view = LayoutInflater.from(this).inflate(R.layout.pop_preset_watchcar, null);
                PopupWindow popWindow1 = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
                popWindow1.setBackgroundDrawable(new ColorDrawable(0xffffff));
                popWindow1.setFocusable(true);
                popWindow1.setOutsideTouchable(true);
                popWindow1.setTouchable(true);
                setAlpha(0.6f);
                popWindow1.showAtLocation(bt_preset, Gravity.CENTER,0,0);
                popWindow1.setOnDismissListener(new PopupWindow.OnDismissListener() {
                    @Override
                    public void onDismiss() {
                        setAlpha(1);
                    }
                });
                break;
        }
    }

    private void initView() {
        finish = (ImageButton) findViewById(R.id.finish);
        et_name = (EditText) findViewById(R.id.et_name);
        et_tel = (EditText) findViewById(R.id.et_tel);
        bt_preset = (Button) findViewById(R.id.bt_preset);

        finish.setOnClickListener(this);
        bt_preset.setOnClickListener(this);
        et_name.setOnClickListener(this);
        et_tel.setOnClickListener(this);
    }

    public void setAlpha(float alpha) {
        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.alpha = alpha;
        window.setAttributes(params);
    }
}
